#include "AlapForm.h"

using namespace Osp::Base;
using namespace Osp::Ui;
using namespace Osp::Ui::Controls;
using namespace Osp::Uix;

AlapForm::AlapForm(void)
{
}

AlapForm::~AlapForm(void)
{
}

bool
AlapForm::Initialize()
{
	// Construct an XML form
	Construct(L"IDF_ALAPFORM");

	return true;
}

result
AlapForm::OnInitializing(void)
{
	result r = E_SUCCESS;

	__pPitchLabel = static_cast<Label *>(GetControl(L"PITCHLABEL"));
	__pRollLabel = static_cast<Label *>(GetControl(L"ROLLLABEL"));
	__pAzimuthLabel = static_cast<Label *>(GetControl(L"AZIMUTHLABEL"));

	manager.Construct();
	if(manager.IsAvailable(SENSOR_TYPE_TILT))
	{
		manager.AddSensorListener(*this, SENSOR_TYPE_TILT , 25, true);
	}

	return r;
}

result
AlapForm::OnTerminating(void)
{
	result r = E_SUCCESS;

	// TODO: Add your termination code here

	return r;
}

void
AlapForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
{
}

void AlapForm::OnDataReceived(SensorType sensorType, SensorData& sensorData , result r)
{
if(r!=E_SUCCESS || sensorType!=SENSOR_TYPE_TILT) return;
	sensorData.GetValue((SensorDataKey)TILT_DATA_KEY_PITCH, pitch);
	sensorData.GetValue((SensorDataKey)TILT_DATA_KEY_AZIMUTH, azimuth);
	sensorData.GetValue((SensorDataKey)TILT_DATA_KEY_ROLL, roll);

	__pPitchLabel->SetText(Osp::Base::Float::ToString(pitch));
	__pRollLabel->SetText(Osp::Base::Float::ToString(roll));
	__pAzimuthLabel->SetText(Osp::Base::Float::ToString(azimuth));
	RequestRedraw();
}

